package com.ruoyi;

import com.zaxxer.hikari.HikariDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration;
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * 启动程序
 *
 */
@SpringBootApplication(exclude = {
        JmxAutoConfiguration.class,
        CassandraAutoConfiguration.class,
        CouchbaseAutoConfiguration.class,
        EmbeddedLdapAutoConfiguration.class,
        FreeMarkerAutoConfiguration.class,
        LdapAutoConfiguration.class,
        RabbitAutoConfiguration.class,
        SolrAutoConfiguration.class })
@MapperScan("com.ruoyi.*.mapper")
public class BaiApplication implements EnvironmentAware
{
    public static void main(String[] args)
    {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication app = new SpringApplication(BaiApplication.class);
        app.setBannerMode(Banner.Mode.OFF);//现在的版本没有setShowBanner(false)方法了
        app.run(args);
        System.out.println("(♥◠‿◠)ﾉﾞ  Springboot系统启动成功   ლ(´ڡ`ლ)ﾞ ");
    }

    @Bean(name="dataSource")
    public DataSource datasource() {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl(env.getProperty("spring.datasource.url"));
        ds.setUsername(env.getProperty("spring.datasource.user"));
        ds.setPassword(env.getProperty("spring.datasource.password"));
        ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
        return ds;
    }

    private Environment env;
    @Override
    public void setEnvironment(Environment environment) {
        this.env=environment;
    }
}